import { createRouter, createWebHistory } from "vue-router";

const routers = [
    {
        path: '/',
        redirect: 'login'
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('../components/Login.vue')
    },
    {
        path: '/main',
        name: 'main',
        component: () => import('../components/Main.vue'),
        children: [
            {
                path: "",
                component: () => import('../components/SystemHomePage.vue')
            },
            {
                path: "Base_Manage/Dept",
                component: () => import('../components/Base_Manage/Dept.vue')
            },
            {
                path: "Base_Manage/User",
                component: () => import('../components/Base_Manage/User.vue')
            },
            {
                path: "DB/MeasureBase",
                component: () => import('../components/DB/MeasureBase.vue')
            },
            {
                path: "DB/ProductType",
                component: () => import("../components/DB/ProductType.vue")
            },
            {
                path: "DB/WarehouseInfo",
                meta: { title: "仓库设置" },
                component: () => import('../components/DB/WarehouseInfo.vue')
            },
            {
                path: "DB/WarehouseareaInfo/:warehouse_code?",
                meta: { title: "库区设置" },
                component: () => import('../components/DB/WarehouseareaInfo.vue')
            },
            {
                path: "DB/WarehousearLocation/:zone_code?",
                meta: { title: "库位设置" },
                component: () => import('../components/DB/WarehousearLocation.vue')
            },
            {
                path: "DB/ProductInfo",
                component: () => import('../components/DB/ProductInfo.vue')
            },
            {
                path: "DB/ProductAdd",
                meta: { title: "产品信息添加" },
                component: () => import('../components/DB/ProductAdd.vue')
            },
            {
                path: "Base_Manage/Dicttype",
                component: () => import('../components/Base_Manage/Dicttype.vue')
            },
            {
                path: "DB/ProductUpdate",
                meta: { title: "产品信息编辑" },
                component: () => import('../components/DB/ProductUpdate.vue')
            },
            {
                path: "DB/ProductInfoPage",
                meta: { title: "产品详情" },
                component: () => import('../components/DB/ProductInfoPage.vue')
            },
            {
                path: "Base_Manage/Dictdata",
                component: () => import('../components/Base_Manage/Dictdata.vue')
            },
            {
                path: "Sinv/CustomerManagement",
                component: () => import('../components/Sinv/CustomerManagement.vue')
            },
            {
                path: "Sinv/CustomerAdd",
                meta: { title: "客户信息添加" },
                component: () => import('../components/Sinv/CustomerAdd.vue')
            },
            {
                path: "Pinv/vendor",
                component: () => import('../components/Pinv/vendor.vue')
            },
            {
                path: "Sinv/CustomerUpdate",
                meta: { title: "客户信息编辑" },
                component: () => import('../components/Sinv/CustomerUpdate.vue')
            },
            {
                path: "Sinv/SalesOrder",
                component: () => import('../components/Sinv/SalesOrder.vue')
            },
            {
                path: "Sinv/CustomerInfo",
                meta: { title: "客户详情" },
                component: () => import('../components/Sinv/CustomerInfo.vue')
            },
            {
                path: "Sinv/SalesOrderAdd",
                meta: { title: "销售订单添加" },
                component: () => import('../components/Sinv/SalesOrderAdd.vue')
            },
            {
                path: "Sinv/SalesOrdereInfo",
                meta: { title: "销售订单详情" },
                component: () => import('../components/Sinv/SalesOrdereInfo.vue')
            },
            {
                path: "Pinv/vendorUpdate",
                meta: { title: "供应商修改" },
                component: () => import('../components/Pinv/Inv_warehousestock.vue')
            },
            {
                path: "Pinv/vendorinfo",
                meta: { title: "供应商详情" },
                component: () => import('../components/Pinv/vendorinfo.vue')
            },
            {
                path: "Inv/OtherWarehouseDetails",
                meta: { title: "其他入库单详情" },
                component: () => import('../components/Inv/OtherWarehouseDetails.vue')
            },
            {
                path: "Inv/OtherWarehouseReceipts",
                meta: { title: "其他入库单" },
                component: () => import('../components/Inv/OtherWarehouseReceipts.vue')
            },
            {
                path: "Inv/InvotherWarehouseAdd",
                meta: { title: "其他入库单添加" },
                component: () => import('../components/Inv/InvotherWarehouseAdd.vue')
            },
            {
                path: "Sinv/SalesOutbound",
                component: () => import('../components/Sinv/SalesOutbound.vue')
            },
            {
                path: "Sinv/SalesOutboundAdd",
                meta: { title: "销售出库添加" },
                component: () => import('../components/Sinv/SalesOutboundAdd.vue')
            },
            {
                path: "Sinv/SalesOrderUpdate",
                meta: { title: "销售订单编辑" },
                component: () => import('../components/Sinv/SalesOrderUpdate.vue')
            },
            {
                path: "Pinv/vendorAdd",
                meta: { title: "供应商信息添加" },
                component: () => import('../components/Pinv/vendorAdd.vue')
            },
            {
                path: "Pinv/Po",
                component: () => import('../components/Pinv/Po.vue')
            },
            {
                path: "Pinv/PoAdd",
                meta: { title: "采购订单添加" },
                component: () => import('../components/Pinv/PoAdd.vue')
            },
            {
                path: "Pinv/Poinfo",
                meta: { title: "采购订单详情" },
                component: () => import('../components/Pinv/Poinfo.vue')
            },
            {
                path: "Pinv/PoUpdate",
                meta: { title: "采购订单编辑" },
                component: () => import('../components/Pinv/PoUpdate.vue')
            },
            {
                path: "Sinv/SalesOutboundUpdate",
                meta: { title: "销售出库编辑" },
                component: () => import('../components/Sinv/SalesOutboundUpdate.vue')
            },
            {
                path: "Sinv/SalesOutboundInfo",
                meta: { title: "销售出库详情" },
                component: () => import('../components/Sinv/SalesOutboundInfo.vue')
            },
            {
                path: "Sinv/SalesReturn",
                component: () => import('../components/Sinv/SalesReturn.vue')
            },
            {
                path: "Sinv/SalesReturnAdd",
                meta: { title: "销售退货添加" },
                component: () => import('../components/Sinv/SalesReturnAdd.vue')
            },
            {
                path: "Inv/OtherWarehouseUpdate/:othwr_code?",
                meta: { title: "其他入库单修改" },
                component: () => import('../components/Inv/OtherWarehouseUpdate.vue')
            },
            {
                path: "Sinv/SalesReturnUpdate",
                meta: { title: "销售退货编辑" },
                component: () => import('../components/Sinv/SalesReturnUpdate.vue')
            },
            {
                path: "Pinv/Pbinfo",
                meta: { title: "采购入库详情" },
                component: () => import('../components/Pinv/Pbinfo.vue')
            },
            {
                path: "Pinv/PbAdd",
                meta: { title: "采购入库添加" },
                component: () => import('../components/Pinv/PbAdd.vue')
            },
            {
                path: "Pinv/PbUpdate",
                meta: { title: "采购入库修改" },
                component: () => import('../components/Pinv/PbUpdate.vue')
            },
            {
                path: "Pinv/Pb",
                meta: { title: "采购入库" },
                component: () => import('../components/Pinv/Pb.vue')
            },
            {
                path: "Pinv/Pu",
                meta: { title: "采购退货" },
                component: () => import('../components/Pinv/Pu.vue')
            },
            {
                path: "Pinv/Puinfo",
                meta: { title: "采购退货详情" },
                component: () => import('../components/Pinv/Puinfo.vue')
            },
            {
                path: "Pinv/PuUpdate",
                meta: { title: "采购退货修改" },
                component: () => import('../components/Pinv/PuUpdate.vue')
            },
            {
                path: "Pinv/PuAdd",
                meta: { title: "采购退货添加" },
                component: () => import('../components/Pinv/PuAdd.vue')
            },
            {
                path: "Pinv/PShow",
                meta: { title: "采购统计信息" },
                component: () => import('../components/Pinv/PShow.vue')
            },
            {
                path: "FG/Picking",
                meta: { title: "领料出库" },
                component: () => import('../components/FG/Picking.vue')
            },
            {
                path: "FG/PickingAdd",
                meta: { title: "领料出库添加" },
                component: () => import('../components/FG/PickingAdd.vue')
            },
            {
                path: "FG/PickingUpdate",
                meta: { title: "领料出库修改" },
                component: () => import('../components/FG/PickingUpdate.vue')
            },
            {
                path: "FG/PickingInfo",
                meta: { title: "领料出库详情" },
                component: () => import('../components/FG/PickingInfo.vue')
            },
            {
                path: "Inv/InvTrf",
                meta: { title: "库存调拨" },
                component: () => import('../components/Inv/InvTrf.vue')
            },
            {
                path: "Inv/InvTrfDetails/:trf_code?",
                meta: { title: "库存调拨详情" },
                component: () => import('../components/Inv/InvTrfDetails.vue')
            },
            {
                path: "Inv/InvTrfAdd",
                meta: { title: "库存调拨添加" },
                component: () => import('../components/Inv/InvTrfAdd.vue')
            },
            {
                path: "Inv/InvTrfUpdate/:trf_code?",
                meta: { title: "库存调拨修改" },
                component: () => import('../components/Inv/InvTrfUpdate.vue')
            },
            {
                path: "Inv/InvQty",
                meta: { title: "库存盘点" },
                component: () => import('../components/Inv/InvQty.vue')
            },
            {
                path: "Inv/InvQtyDetails/:qty_code?",
                meta: { title: "库存盘点详情" },
                component: () => import('../components/Inv/InvQtyDetails.vue')
            },
            {
                path: "Inv/InvQtyAdd",
                meta: { title: "库存盘点添加" },
                component: () => import('../components/Inv/InvQtyAdd.vue')
            },
            {
                path: "Inv/InvQtyUpdate/:qty_code?",
                meta: { title: "库存盘点修改" },
                component: () => import('../components/Inv/InvQtyUpdate.vue')
            },
            {
                path: "Inv/InvSamp",
                meta: { title: "库存抽检" },
                component: () => import('../components/Inv/InvSamp.vue')
            },
            {
                path: "Inv/InvSampDetails/:samp_code?",
                meta: { title: "库存抽检详情" },
                component: () => import('../components/Inv/InvSampDetails.vue')
            },
            {
                path: "Inv/InvSampAdd",
                meta: { title: "抽检单添加" },
                component: () => import('../components/Inv/InvSampAdd.vue')
            },
            {
                path: "Inv/InvSampUpdate/:samp_code?",
                meta: { title: "抽检单修改" },
                component: () => import('../components/Inv/InvSampUpdate.vue')
            },
            {
                path: "FG/FinishedGoodsStore",
                component: () => import('../components/FG/FinishedGoodsStore.vue')
            },
            {
                path: "FG/FinishedGoodsStoreAdd",
                meta: { title: "成品入库添加" },
                component: () => import('../components/FG/FinishedGoodsStoreAdd.vue')
            },
            {
                path: "FG/FinishedGoodsStoreUpdate",
                meta: { title: "成品入库编辑" },
                component: () => import('../components/FG/FinishedGoodsStoreUpdate.vue')
            },
            {
                path: "FG/FinishedGoodsStoreInfo",
                meta: { title: "成品入库详情" },
                component: () => import('../components/FG/FinishedGoodsStoreInfo.vue')
            },
            {
                path: "Sinv/SalesReturnInfo",
                meta: { title: "销售退货详情" },
                component: () => import('../components/Sinv/SalesReturnInfo.vue')
            },
            {
                path: "Inv/Inv_othoutordVue",
                component: () => import('../components/Inv/Inv_othoutordVue.vue')
            },
            {
                path: "Inv/Inv_othoutordDetails/:Othoutord_code?",
                meta: { title: "其他出库详情" },
                component: () => import('../components/Inv/Inv_othoutordDetails.vue')
            },
            {
                path: "Inv/Inv_othoutorAdd",
                meta: { title: "其他出库单添加" },
                component: () => import('../components/Inv/Inv_othoutorAdd.vue')
            },
            {
                path: "Inv/Inv_othoutorUpdate/:Othoutord_code?",
                meta: { title: "其他出库单修改" },
                component: () => import('../components/Inv/Inv_othoutorUpdate.vue')
            },{
                path: "Inv/Inv_warehousestock",
                meta: { title: "仓库库存" },
                component: () => import('../components/Inv/Inv_warehousestock.vue')
            },{
                path: "Inv/Amap",
                meta: { title: "仓库位置选择" },
                component: () => import('../components/Inv/Amap.vue')
            }
        ]
    }
];

// 创建路由对象   Inv_othoutorUpdate  
const router = createRouter({
    history: createWebHistory(),
    routes: routers
});

// 路由守卫
router.beforeEach((to, from, next) => {
    if (to.path !== "/login") {
        if (localStorage.getItem('token')) {
            next();
        } else {
            alert('请登录后再次进入！');
            next('/login');
        }
    } else {
        next();
    }
});

// 导出路由对象
export default router;